package android.src.main.km_printer_plugin.receiver;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.android.print.sdk.PrinterConstants;
import android.src.main.km_printer_plugin.manager.PrintfManager;


public class NameOfBroadcastReceiverClass extends BroadcastReceiver {

    private final String TAG = "BroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {//蓝牙连接已经断开
            PrintfManager.getInstance(context).mHandler.sendEmptyMessage(PrinterConstants.Connect.CLOSED);
        }
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                    BluetoothAdapter.ERROR);
            if (state == BluetoothAdapter.STATE_OFF) {//蓝牙关闭
                PrintfManager.getInstance(context).mHandler.sendEmptyMessage(PrinterConstants.Connect.CLOSED);
            }
        }
    }
}
